package com.pet_service.controller;

import com.pet_service.entity.PetCategory;
import com.pet_service.result.Result;
import com.pet_service.service.PetCategoryService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 邹全伸
 * @version 1.0
 * @date 2025-10-04 11:06
 */
@RestController
@Slf4j
@RequestMapping("/app/home")
@Tag(name = "首页模块")
public class HomeController {
    @Resource
    private PetCategoryService petCategoryService;

    //获取首页一级分类（如：猫、狗、鸟等）
    @GetMapping("/categories")
    public Result<List<PetCategory>> getCategories() {
        List<PetCategory> rootCategories = petCategoryService.getRootCategories();
        return Result.ok(rootCategories);
    }

    //获取某个分类下的子分类（如：点击“猫” -> 显示布偶猫、英短等）
    @GetMapping("/categories/{parent_id}")
    public Result<List<PetCategory>> getChildCategories(@PathVariable Integer parent_id) {
        List<PetCategory> childCategories = petCategoryService.getChildCategories(parent_id);
        return Result.ok(childCategories);
    }


}
